package org.mysocial.datamodel;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * @author ivan
 * @version 1.0
 * @created 21-Jul-2011 10:00:25 PM
 */
@Entity
@Table(name = "post")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@NamedQueries(@NamedQuery(name = Post.GET_ACCOUNT_POSTS, query = "select p from Post p where account = ?"))
public abstract class Post implements Serializable
{
	public static final String GET_ACCOUNT_POSTS = "GET_ACCOUNT_POSTS";

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private long id;

	@Column(name = "text")
	private String text;

	@Column(name = "time")
	private Date time;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "account_fk")
	private Account account;

	@OneToMany(mappedBy = "post", fetch = FetchType.EAGER)
	private Set<Comment> comments;

	@OneToMany(mappedBy = "post", fetch = FetchType.EAGER)
	private Set<Like> likes;

	@OneToMany(mappedBy = "post", fetch = FetchType.EAGER)
	private Set<Tag> tags;

	public Account getAccount()
	{
		return account;
	}

	public Set<Comment> getComments()
	{
		return comments;
	}

	public long getId()
	{
		return id;
	}

	public Set<Like> getLikes()
	{
		return likes;
	}

	public Set<Tag> getTags()
	{
		return tags;
	}

	public String getText()
	{
		return text;
	}

	public Date getTime()
	{
		return time;
	}

	public void setAccount(Account account)
	{
		this.account = account;
	}

	public void setComments(Set<Comment> comments)
	{
		this.comments = comments;
	}

	public void setId(long id)
	{
		this.id = id;
	}

	public void setLikes(Set<Like> likes)
	{
		this.likes = likes;
	}

	public void setTags(Set<Tag> tags)
	{
		this.tags = tags;
	}

	public void setText(String text)
	{
		this.text = text;
	}

	public void setTime(Date time)
	{
		this.time = time;
	}
}